package com.qcby.controller;

import com.qcby.common.Result;
import com.qcby.entity.TCategory;
import com.qcby.entity.TProductSpecification;
import com.qcby.form.TCategoryListForm;
import com.qcby.form.TProductSpecificationFrom;
import com.qcby.form.TProductSpecificationForm;
import com.qcby.service.TCategoryService;
import com.qcby.service.TProductSpecificationService;
import com.qcby.vo.TProductSpecificationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品规格 前端控制器
 * </p>
 *
 * @author admin
 * @since 2025-02-04
 */
@Controller
@RequestMapping("/product-specification")
public class TProductSpecificationController {
    @Autowired
    private TProductSpecificationService specificationService;

    /**
     * 获取商品规格列表
     */
    @GetMapping("/list/{productId}")
    public Result<List<TProductSpecificationVO>> list(@PathVariable("productId") Integer productId) {
        List<TProductSpecificationVO> list = specificationService.getSpecificationList(productId);
        return Result.success(list);
    }

    /**
     * 添加商品规格
     */
    @PostMapping
    public Result add(@RequestBody @Valid TProductSpecificationForm form) {
        specificationService.addSpecification(form);
        return Result.success();
    }

    /**
     * 修改商品规格
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable("id") Integer id, @RequestBody @Valid TProductSpecificationForm form) {
        specificationService.updateSpecification(id, form);
        return Result.success();
    }

    /**
     * 删除商品规格
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        specificationService.deleteSpecification(id);
        return Result.success();
    }
}

